
package com.vt.admin.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.vt.admin.api.dto.SysRoleListDto;
import com.vt.admin.api.dto.SysMenuTreeDto;
import com.vt.admin.api.entity.SysRole;
import com.vt.admin.api.param.RoleMenuPermission;
import com.vt.admin.api.param.SysRoleListParam;
import com.vt.admin.service.SysRoleService;
import com.vt.common.core.util.R;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/role")
@AllArgsConstructor
public class RoleController {
    private SysRoleService service;

    @GetMapping
    public Page<SysRoleListDto> list(SysRoleListParam param) {
        return service.list(param);
    }

    @GetMapping("{id}")
    public R<SysRole> findOne(@PathVariable("id") String id) {
        return service.findOne(id);
    }

    @PostMapping
    public R<Boolean> save(@RequestBody SysRole role) {
        return service.save(role);
    }

    @GetMapping("/menuPermission/{roleId}")
    public R<List<SysMenuTreeDto>> findMenuPermission(@PathVariable("roleId") String roleId) {
        return service.findMenuPermission(roleId);
    }

    @PostMapping("/menuPermission")
    public R<Boolean> saveMenuPermission(@RequestBody RoleMenuPermission param){
        return service.saveMenuPermission(param);
    }

    @DeleteMapping("{id}")
    public R<Boolean> delete(@PathVariable("id") String id){
        return service.delete(id);
    }

    @PostMapping("enable")
    public R<Boolean> enable(@RequestBody SysRole role){
        return service.enable(role);
    }

    @GetMapping("findByCompany")
    public R<List<SysRole>> findByCompany(@RequestParam(defaultValue = "") String managerId) {
        return service.findByCompany(managerId);
    }
}
